import { chunk } from "./chunk";
class ShaderPool{
    constructor(){
        this.merge("Geometry");
        this.merge("PointGeometry")
        this.merge("LineGeometry")
        this.merge("BasicMaterial");
        this.merge("StandardMaterial");
        this.merge("SkyboxGeometry")
        this.merge("SkyboxMaterial")
        this.merge("VertexShadow")
        this.merge("PointShadowVertex")
        this.merge("PointShadowFrag")
        this.merge("PointsGeometry")
        this.merge("PointMaterial")
    }
    /**
     * 合并着色器
     * @param {String} main 着色器名称
     */
    merge(main){
        let pattern = /^[ \t]*#include +<([\w\d.]+)>/gm;
        let replaceItem = new Set();
        let replaceFn = function (match, include) {
            if (replaceItem.has(include)) {
                return ""
            } else {
                replaceItem.add(include)
                return chunk.common[include];
            }
        };
        let code=chunk.main[main];
        let source=code.replace(pattern, replaceFn);
        source=source.replaceAll("~","$");
        source=source.trim();
        this[main]=source;
    }
}
export {ShaderPool}